package Mooc.Chap1;

public class Vending {
    int price = 80;
    int balance;
    int total;

    //和类同名的构造函数，没有返回类型，创建一个实例,会自动运行,,也就是可以在这设置输入参数
    Vending() {
        price = 60;
    }

    //重载，有两个构造函数，会根据输入参数自动选择
    Vending(int price) {
        this.price = price;
    }

    void setPrice(int price) {
        this.price = price;
    }

    void showPrompt() {
        System.out.println("Welcome");
    }

    void insertMoney(int amount) {
        balance = balance + amount;
        showBalance();
    }

    void showBalance() {
        System.out.println(balance);
//        System.out.println(this.balance)
    }

    void getFood() {
        if (balance >= price) {
            System.out.println("Here you are.");
            balance = balance - price;
            total = total + price;
        }
    }

    public static void main(String[] args) {
        System.out.println("Hello World!");
        Vending vm = new Vending();
        vm.setPrice(60);
        vm.showPrompt();
        vm.showBalance();
        vm.insertMoney(100);
        vm.getFood();
        vm.showBalance();
    }
}
